package com.anhuanjia.tools.eao.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.springframework.util.StringUtils;

import com.anhuanjia.tools.eao.bean.EaoAudit;
import com.anhuanjia.tools.eao.bean.EaoProjectInfo;
import com.anhuanjia.tools.eao.bean.EaoProjectStaff;
import com.anhuanjia.tools.eao.beanvo.EaoEngineerMemberVo;
import com.anhuanjia.tools.eao.beanvo.EaoProjectAssignVo;
import com.efastsoft.framework.Member;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.data.Transaction;
import com.efastsoft.framework.i18n.Lang;
import com.efastsoft.framework.utility.StringUtil;

/**
 * 分配项目操作类
 * 
 * @author Administrator
 *
 */
@Alias(value = "assignjobs")
public class AssignJobsUI extends UIFacade {

	/**
	 * 获取项目编号、项目级别
	 */
	@Priv(loginType = LoginType.Member)
	public void isFcompany() {
		String id = $V("Id");
		if (StringUtil.isNotEmpty(id)) {
			DataTable dt = new Q("Select ProjectNumber,ProjectLevel from eao_project_info where Id = ?", id).fetch();
			$S("data", dt);
		} else {
			f("参数传入失败");
		}
	}

	/**
	 * 判断项目是否已分配
	 */
	@Priv(loginType = LoginType.Member)
	public void isAssignJobs() {
		String id = $V("Id");
		if(StringUtils.isEmpty(id)) {
			f("参数传入失败");
		}
		DataTable dt = new Q("Select IsAssign from eao_project_info where Id = ?", id).fetch();
		if (dt.getRowCount() != 0) {
			$S("stats", dt.get(0, "IsAssign"));
		} else {
			f("没有查到数据");
		}

	}

	/**
	 * 设置项目负责人 z
	 */
	@Priv(loginType = LoginType.Member)
	public void setProjectLeader() {
		String projectid = $V("ProjectId"); // 获取项目编号
		String leader = $V("PerjectLeader"); // 获取负责人的resource表id
		String creater = $V("CreatePerson"); // 设置创建人resource表id
		if (StringUtils.isEmpty(projectid) && StringUtils.isEmpty(leader)) {
			f("操作失败！");
			return;
		}
		Transaction transaction = new Transaction();
		DataTable dt = new Q(" select * from eao_project_info where Id = ?", projectid).fetch();
		EaoProjectInfo old = new EaoProjectInfo();
		old.setValue(dt.get(0));
		if (!creater.isEmpty()) {
			old.setCreatePerson(Integer.valueOf(creater));
		}
		old.setPerjectLeader(Integer.valueOf(leader));
		transaction.update(old);
		if (transaction.commit()) {
			s(Lang.get("Common.ExecuteSuccess"));
		} else {
			f(Lang.get("Common.ExecuteFailed"));
		}

	}

	/**
	 * 设置审核修改人员
	 */
	@Priv(loginType = LoginType.Member)
	public void setModifier() {
		Transaction transaction = new Transaction();
		String pid = $V("ProjectId");
		String type = $V("Atype");
		String mid = $V("Modifier");
		if (StringUtils.isEmpty(pid) || StringUtils.isEmpty(type) || StringUtils.isEmpty(mid)) {
			f("操作失败！");
			return;
		}
		DataTable dt = new Q("Select * from eao_audit where ProjectId =? AND AuditType=?", pid, type).fetch();
		EaoAudit entity = new EaoAudit();
		for (DataRow dr : dt) {
			entity.setValue(dr);
		}
		entity.setModifier(mid);
		transaction.update(entity);
		if (transaction.commit()) {
			s(Lang.get("Common.ExecuteSuccess"));
		} else {
			f(Lang.get("Common.ExecuteFailed"));
		}
	}

	/**
	 * 总工、总经理 统一分配设置 z
	 */
	@Priv(loginType = LoginType.Member)
	public void doassignjobs() {
		String projectid = $V("ProjectId"); // 获取项目编号
		String leader = $V("PerjectLeader"); // 获取负责人的resource表id
		String staff = $V("StaffName"); // 获取小组成员数据 多个逗号隔开
		String yname = $V("Yname"); // 一审工程师
		String ename = $V("Ename"); // 二审工程师
		String cname = $V("Cname"); // 初审工程师
		String fname = $V("Fname");// 复审工程师
		String zname = $V("Zname");// 终审工程师
		Boolean isStaff = true;
		if (StringUtils.isEmpty(projectid) && StringUtils.isEmpty(cname) && StringUtils.isEmpty(fname)
				&& StringUtils.isEmpty(zname)) {
			f("操作失败！");
			return;
		}
		if (StringUtils.isEmpty(yname) || "0".equals(yname)) {
			yname = new Q(" select auditor from eao_audit where AuditType = '一审' and ProjectId = ?", projectid)
					.executeString();
		}
		if (StringUtils.isEmpty(ename) || "0".equals(ename)) {
			ename = new Q(" select auditor from eao_audit where AuditType = '二审' and ProjectId = ?", projectid)
					.executeString();
		}
		if (StringUtils.isEmpty(leader) || "0".equals(leader)) {
			leader = new Q(" select PerjectLeader from eao_project_info where Id = ?", projectid).executeString();
		}
		if (StringUtils.isEmpty(staff) || "0".equals(staff)) {
			isStaff = false;
			staff = new Q(" select GROUP_CONCAT(StaffName) as Staff from eao_project_staff where ProjectId = ?",
					projectid).executeString();
		}
		if (StringUtil.isNotEmpty(yname) && StringUtil.isNotEmpty(ename)) {
			if (yname.equals(ename) || yname.equals(cname) || yname.equals(fname) || yname.equals(zname)
					|| ename.equals(cname) || ename.equals(fname) || ename.equals(zname)) {
				f("审核人员不能重复");
				return;
			}
		}
		if ((StringUtil.isNotEmpty(cname) || "0".equals(cname)) && (StringUtil.isNotEmpty(fname) || "0".equals(fname))
				&& (StringUtil.isNotEmpty(zname) || "0".equals(zname))) {
			if (cname.equals(fname) || cname.equals(zname) || fname.equals(zname)) {
				f("审核人员不能重复");
				return;
			}
		}
		if (StringUtil.isNotEmpty(leader)) {
			if (leader.equals(cname) || leader.equals(fname) || leader.equals(zname)) {
				f("项目负责人不可做(初/复/终)审人员");
				return;
			}
		}
		if (StringUtil.isNotEmpty(staff)) {
			String Staff_name[] = staff.split(",");
			for (String string : Staff_name) {
				if (string.equals(cname) || string.equals(fname) || string.equals(zname)) {
					f("项目组成员不可做(初/复/终)审人员");
					return;
				}
			}
		}
		Transaction transaction = new Transaction();
		DataTable dt = new Q("select CreatePerson,ProjectLevel,Tof from eao_project_info where Id = ?", projectid)
				.fetch();
		// 获取公司级别 0总公司 1分公司
		String plevel = "";
		Integer Create_person = null;
		String tof = null;
		for (DataRow dr : dt) {
			Create_person = dr.getInt("CreatePerson");
			plevel = dr.getString("ProjectLevel");
			tof = dr.getString("Tof");
		}

		if ("0".equals(plevel)) {
			if (isStaff) {
				String staffs[] = staff.split(",");
				int stf[] = new int[staffs.length];
				for (int i = 0; i < staffs.length; i++) {
					stf[i] = Integer.parseInt(staffs[i]);
				}
				Boolean bl = true;
				Boolean blCreate = true;
				String table = new Q(" select IsEngineer from eao_is_engineer where Member = ? ", Create_person)
						.executeString();
				String table1 = new Q(" select ParentId from eao_position where Id = ? ", table).executeString();
				if (StringUtil.isNotEmpty(table1)) {
					table = table1;
				}
				if ("4".equals(table) || "5".equals(table) || "6".equals(table)) {
					blCreate = true;
					if (Create_person.toString().equals(cname) || Create_person.toString().equals(fname)
							|| Create_person.toString().equals(zname)) {
						f("如果要将属于技术员和工程师角色的项目提交人选为初审、复审或者终审工程师，需要在已分配界面进行操作。");
						return;
					}
				} else {
					blCreate = false;
				}
				HashSet<String> set = new HashSet<String>(staffs.length);
				List<String> result = new ArrayList<String>(staffs.length);
				for (String str : staffs) {
					if (set.add(str)) {
						result.add(str);
					}
				}
				for (String str : result) { // 设置小组成员
					if (leader.equals(str)) {
						bl = false;
					}
					if (Create_person.toString().equals(str)) {
						blCreate = false;
					}
					if (!leader.equals(str)) {
						EaoProjectStaff entity = new EaoProjectStaff();
						entity.setId(UUID.randomUUID().toString());
						entity.setProjectId(projectid);
						entity.setStaffName(Integer.valueOf(str));
						entity.insert();
					}
					if (leader.equals(str)) {
						EaoProjectStaff entity = new EaoProjectStaff();
						entity.setId(UUID.randomUUID().toString());
						entity.setProjectId(projectid);
						entity.setStaffName(Integer.valueOf(str));
						entity.insert();
					}
				}
				if (blCreate) {
					EaoProjectStaff entity = new EaoProjectStaff();
					entity.setId(UUID.randomUUID().toString());
					entity.setProjectId(projectid);
					entity.setStaffName(Create_person);
					transaction.insert(entity);
				}
				if (bl) {
					EaoProjectStaff entity = new EaoProjectStaff();
					entity.setId(UUID.randomUUID().toString());
					entity.setProjectId(projectid);
					entity.setStaffName(Integer.parseInt(leader));
					transaction.insert(entity);
				}
				if (transaction.commit()) {
					s(Lang.get("Common.ExecuteSuccess"));
				} else {
					f(Lang.get("Common.ExecuteFailed"));
				}
			}
			DataTable dtOne = new Q(" select * from eao_project_info where Id = ?", projectid).fetch();
			EaoProjectInfo old = new EaoProjectInfo();
			old.setValue(dtOne.get(0));
			int leaderi = Integer.parseInt(leader);
			old.setPerjectLeader(leaderi);
			transaction.update(old);
			if ("1".equals(tof)) {
				if (StringUtils.isEmpty(yname) && StringUtils.isEmpty(ename)) {
					f("请设置一审二审工程师！");
					return;
				}
				EaoAudit yold = new EaoAudit();
				yold.setId(UUID.randomUUID().toString());
				yold.setProjectId(projectid);
				yold.setStats("未提交");
				yold.setAuditor(yname);
				yold.setAuditType("一审");
				transaction.insert(yold);
				EaoAudit eold = new EaoAudit();
				eold.setId(UUID.randomUUID().toString());
				eold.setProjectId(projectid);
				eold.setStats("未提交");
				eold.setAuditor(ename);
				eold.setAuditType("二审");
				transaction.insert(eold);
			}
			if (transaction.commit()) {
				s(Lang.get("Common.ExecuteSuccess"));
			} else {
				f(Lang.get("Common.ExecuteFailed"));
			}
		}
		EaoAudit cold = new EaoAudit();
		cold.setId(UUID.randomUUID().toString());
		cold.setProjectId(projectid);
		cold.setStats("未提交");
		cold.setAuditor(cname);
		cold.setAuditType("初审");
		transaction.insert(cold);
		EaoAudit fold = new EaoAudit();
		fold.setId(UUID.randomUUID().toString());
		fold.setProjectId(projectid);
		fold.setStats("未提交");
		fold.setAuditor(fname);
		fold.setAuditType("复审");
		transaction.insert(fold);
		EaoAudit zold = new EaoAudit();
		zold.setId(UUID.randomUUID().toString());
		zold.setProjectId(projectid);
		zold.setStats("未提交");
		zold.setAuditor(zname);
		zold.setAuditType("终审");
		transaction.insert(zold);
		DataTable dtTwo = new Q(" select * from eao_project_info where Id = ?", projectid).fetch();
		EaoProjectInfo oldTwo = new EaoProjectInfo();
		oldTwo.setValue(dtTwo.get(0));
		oldTwo.setPerjectType(2);
		oldTwo.setIsAssign("1");
		transaction.update(oldTwo);
		if (transaction.commit()) {
			s(Lang.get("Common.ExecuteSuccess"));
		} else {
			f(Lang.get("Common.ExecuteFailed"));
		}

	}

	/**
	 * 设置分公司一审二审及小组成员 仅供分公司项目负责人调用 z
	 */
	@Priv(loginType = LoginType.Member)
	public void setFCompany() {
		String projectid = $V("ProjectId"); // 获取项目id
		String leader = $V("PerjectLeader"); // 分公司项目负责人
		String ysname = $V("Yname"); // 分公司一审工程师
		String esname = $V("Ename"); // 分公司二审工程师
		String staff = $V("StaffName"); // 获取小组成员数据 多个逗号隔开
		if (StringUtils.isEmpty(projectid) && StringUtils.isEmpty(staff)) {
			f("操作失败！");
			return;
		}
		if (StringUtils.isEmpty(ysname) || "0".equals(ysname)) {
			ysname = new Q(" select Auditor from eao_audit where AuditType = '一审' and ProjectId = ?", projectid)
					.executeString();
		}
		if (StringUtils.isEmpty(esname) || "0".equals(esname)) {
			esname = new Q(" select Auditor from eao_audit where AuditType = '二审' and ProjectId = ?", projectid)
					.executeString();
		}
		if (StringUtil.isNotEmpty(ysname) && StringUtil.isNotEmpty(esname)) {
			if (ysname.equals(esname)) {
				f("审核人员不能重复");
				return;
			}
		}
		DataTable dt = new Q("select * from eao_project_info where Id = ?", projectid).fetch();
		String plevel = "";
		Integer Create_person = null;
		String tof = null;
		EaoProjectInfo projectInfo = new EaoProjectInfo();
		for (DataRow dr : dt) {
			plevel = dr.getString("ProjectLevel");
			Create_person = dr.getInt("CreatePerson");
			tof = dr.getString("Tof");
			projectInfo.setValue(dr);
		}
		if ("0".equals(plevel)) {
			f("操作失败！");
			return;
		}
		String staffs[] = staff.split(",");
		int stf[] = new int[staffs.length];
		Boolean bl = true;
		Boolean blCreate = true;
		String table = new Q(" select IsEngineer from eao_is_engineer where Member = ? ", Create_person)
				.executeString();
		String table1 = new Q(" select ParentId from eao_position where Id = ? ", table).executeString();
		if (StringUtil.isNotEmpty(table1)) {
			table = table1;
		}
		if ("4".equals(table) || "5".equals(table) || "6".equals(table)) {
			blCreate = true;
		} else {
			blCreate = false;
		}
		for (int i = 0; i < staffs.length; i++) {
			stf[i] = Integer.parseInt(staffs[i]);
			if (Integer.parseInt(leader) == stf[i]) {
				bl = false;
			}
			if (Create_person == stf[i]) {
				bl = false;
			}
		}
		if (bl) {
			EaoProjectStaff entity = new EaoProjectStaff();
			entity.setId(UUID.randomUUID().toString());
			entity.setProjectId(projectid);
			entity.setStaffName(Integer.parseInt(leader));
			if (entity.insert()) {
				s(Lang.get("Common.ExecuteSuccess"));
			} else {
				f(Lang.get("Common.ExecuteFailed"));
			}
		}
		if (blCreate) {
			EaoProjectStaff entity = new EaoProjectStaff();
			entity.setId(UUID.randomUUID().toString());
			entity.setProjectId(projectid);
			entity.setStaffName(Create_person);
			if (entity.insert()) {
				s(Lang.get("Common.ExecuteSuccess"));
			} else {
				f(Lang.get("Common.ExecuteFailed"));
			}
		}
		HashSet<String> set = new HashSet<String>(staffs.length);
		List<String> result = new ArrayList<String>(staffs.length);
		for (String str : staffs) {
			if (set.add(str)) {
				result.add(str);
			}
		}
		for (String sta : result) { // 设置小组成员
			if (!leader.equals(sta)) {
				EaoProjectStaff entity = new EaoProjectStaff();
				entity.setId(UUID.randomUUID().toString());
				entity.setProjectId(projectid);
				entity.setStaffName(Integer.valueOf(sta));
				entity.insert();
			}
			if (leader.equals(sta)) {
				EaoProjectStaff entity = new EaoProjectStaff();
				entity.setId(UUID.randomUUID().toString());
				entity.setProjectId(projectid);
				entity.setStaffName(Integer.valueOf(sta));
				entity.insert();
			}
		}

		Transaction transaction = new Transaction();
		if (StringUtil.isEmpty(tof) || "1".equals(tof)) {
			if (StringUtils.isEmpty(ysname) && StringUtils.isEmpty(esname)) {
				f("请设置审核工程师");
				return;
			}
			EaoAudit ysold = new EaoAudit();
			EaoAudit esold = new EaoAudit();
			ysold.setId(UUID.randomUUID().toString());
			ysold.setProjectId(projectid);
			ysold.setStats("未提交");
			ysold.setAuditor(ysname);
			ysold.setAuditType("一审");
			transaction.insert(ysold);
			esold.setId(UUID.randomUUID().toString());
			esold.setProjectId(projectid);
			esold.setStats("未提交");
			esold.setAuditor(esname);
			esold.setAuditType("二审");
			transaction.insert(esold);
		}
		projectInfo.setIsFcAssign("1");
		if (StringUtil.isNotEmpty(leader)) {
			int leaderi = Integer.parseInt(leader);
			projectInfo.setPerjectLeader(leaderi);
		}
		transaction.update(projectInfo);
		if (transaction.commit()) {
			s(Lang.get("Common.ExecuteSuccess"));
		} else {
			f(Lang.get("Common.ExecuteFailed"));
		}
	}

	/**
	 * 设置项目成员
	 */
	@Priv(loginType = LoginType.Member)
	public void setProjectStaff() {
		String id = $V("Id"); // 成员表id
		String projectid = $V("ProjectId");
		String staff = $V("StaffName"); // 多个逗号隔开
		if (StringUtils.isEmpty(projectid) || StringUtils.isEmpty(staff)) {
			f("操作失败！");
			return;
		}

		String staffs[] = staff.split(",");
		int stf[] = new int[staffs.length];
		for (int i = 0; i < staffs.length; i++) {
			stf[i] = Integer.parseInt(staffs[i]);
		}

		EaoProjectStaff entity = new EaoProjectStaff();
		Transaction transaction = new Transaction();
		if (StringUtils.isEmpty(id)) {
			for (int i = 0; i < staffs.length; i++) {
				entity.setId(UUID.randomUUID().toString());
				entity.setProjectId(projectid);
				entity.setStaffName(stf[i]);
				transaction.insert(entity);
			}
		} else {
			DataTable dt = new Q(" select * from eao_project_staff where Id = ?", id).fetch();
			EaoProjectStaff old = new EaoProjectStaff();
			old.setValue(dt.get(0));
			old.setValue(this.Request);
			transaction.update(old);
		}
		if (transaction.commit()) {
			s(Lang.get("Common.ExecuteSuccess"));
		} else {
			f(Lang.get("Common.ExecuteFailed"));
		}
	}

	/**
	 * 查询已分配或未分配项目的信息
	 */
	@Priv(loginType = LoginType.Member)
	public void showProject() {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		pageIndex = (pageIndex - 1) * pageSize;
		String isAssign = $V("IsAssign");
		if (!StringUtils.isEmpty(isAssign)) { // isAssign不为空 返回已分配的数据 为空返回未分配数据
			Q q = new Q(
					"select pj.Id,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,FullName as CommitName,fz.LeaderName,StaffNames,Auditors from eao_project_info as pj LEFT JOIN Mh_Resource as rs ON pj.CreatePerson =rs.Member LEFT JOIN (SELECT Id as ProjectId,PerjectLeader,Member,FullName as LeaderName  from eao_project_info LEFT JOIN Mh_Resource on eao_project_info.PerjectLeader = Mh_Resource.Member)AS fz ON pj.Id = fz.ProjectId LEFT JOIN (select ProjectId,GROUP_CONCAT(StaffsName) as StaffNames from(select  ProjectId,FullName as StaffsName from eao_project_staff as staff LEFT JOIN Mh_Resource on staff.StaffName=Mh_Resource.Member)as cy GROUP BY ProjectId)as cys ON pj.Id = cys.projectId LEFT JOIN (select ProjectId,GROUP_CONCAT(AuditType ,'工程师：',Audname order by AuditType )as auditors from (select ProjectId,Auditor,FullName as Audname,AuditType from eao_audit LEFT JOIN Mh_Resource on eao_audit.Auditor = Mh_Resource.Member) auditorb GROUP BY ProjectId)shb ON pj.Id=shb.ProjectId WHERE IsAssign = 1 ORDER BY ProjectNumber limit ?,?",
					pageIndex, pageSize);
			DataTable dt = new Q(
					"select COUNT(*) as c from eao_project_info as pj LEFT JOIN Mh_Resource as rs ON pj.createPerson =rs.Member LEFT JOIN (SELECT id as projectId,perjectLeader,Member,FullName as leaderName  from eao_project_info LEFT JOIN Mh_Resource on eao_project_info.perjectLeader = Mh_Resource.Member)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames from(select  projectId,FullName as staffsName from eao_project_staff as staff LEFT JOIN Mh_Resource on staff.staffName=Mh_Resource.Member)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN (select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors from (select projectId,auditor,FullName as audname,auditType from eao_audit LEFT JOIN Mh_Resource on eao_audit.auditor = Mh_Resource.Member) auditorb GROUP BY projectId)shb ON pj.id=shb.projectId WHERE IsAssign = 1 ")
							.fetch();
			Integer count = 0;
			for (DataRow dr : dt) {
				count = dr.getInt("c");
			}
			this.Response.put("count", count);
			$S("data", q.fetch());
		} else {
			Q q = new Q(
					"select pj.Id,ProjectNumber,ProjectName,ProjectLevel,ReportType,BuildAddress,FullName as CommitName from eao_project_info as pj LEFT JOIN Mh_Resource as rs ON pj.createPerson = rs.Member  WHERE IsAssign = 0 ORDER BY projectNumber LIMIT ?,?",
					pageIndex, pageSize);
			DataTable dtTwo = new Q(
					"select count(*)as c from eao_project_info as pj LEFT JOIN Mh_Resource as rs ON pj.createPerson = rs.Member  WHERE IsAssign = 0 ")
							.fetch();
			Integer cc = 0;
			for (DataRow dr : dtTwo) {
				cc = dr.getInt("c");
			}
			this.Response.put("count", cc);
			$S("data", q.fetch());
		}

	}

	/**
	 * 查询已分配或未分配项目的信息
	 */
	@Priv(loginType = LoginType.Member)
	public void showFCProject() {
		String loginer = Long.toString(Member.getUID()); // 默认为登录人
		// String loginer = "11";
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		pageIndex = (pageIndex - 1) * pageSize;
		String isAssign = $V("IsAssign");
		DataTable dtZero = new Q(
				"select IsEngineer,Company,BranchInnerCode from Mh_Resource as mr LEFT JOIN eao_is_engineer on mr.Member = eao_is_engineer.Member WHERE  mr.Member =?",
				loginer).fetch();
		String level = "";
		String company = "";
		String bcode = "";
		if (dtZero.getRowCount() != 0) {
			String ParentId = new Q(" select ParentId from eao_Position where Id = ? ", dtZero.getString(0, 0))
					.executeString();
			if (StringUtils.isEmpty(ParentId)) {
				level = dtZero.getString(0, 0);
			} else {
				level = ParentId;
			}
			company = dtZero.getString(0, 1);
			bcode = new Q("select ParentInnerCode from Mh_Branch WHERE BranchInnerCode =?", dtZero.getString(0, 2))
					.executeString();
			if ("0".equals(bcode) || "".equals(bcode)) {
				bcode = dtZero.getString(0, 2);
			}
		}
//		String dataTable = new Q("select CompanyType from Mh_Branch where Company = ? and BranchInnerCode = ?", company,
//				bcode).executeString();
		if ("2".equals(level) || "1".equals(level)) {
			$S("bcode", "z");
		} else {
			$S("bcode", "!z");
		}
		if ("2".equals(level) || "1".equals(level)) {
			if (!StringUtils.isEmpty(isAssign)) { // isAssign不为空 返回已分配的数据 为空返回未分配数据
				Q q = new Q(
						"select pj.IsFcAssign,AuditorC,AuditorD,AuditorE,AuditorF,AuditorG,pj.Id,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,rs.RealName as CommitName,pj.CreatePerson as CommitNameId,fz.LeaderName,pj.PerjectLeader as LeaderNameId,StaffNames,StaffNameIds,Auditors,pj.Tof,AuditorsId from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson =rs.Id LEFT JOIN (SELECT eao_project_info.id as projectId,perjectLeader,Ec_Member.Id,Ec_Member.RealName as leaderName  from eao_project_info LEFT JOIN Ec_Member on eao_project_info.perjectLeader = Ec_Member.Id)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames,GROUP_CONCAT(staffNameId ) as staffNameIds from(select  projectId,RealName as staffsName,staffName as staffNameId from eao_project_staff as staff LEFT JOIN Ec_Member on staff.staffName=Ec_Member.Id)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN(select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors,GROUP_CONCAT(auditor) as auditorsId from (select projectId,auditor,RealName as audname,auditType from eao_audit LEFT JOIN Ec_Member on eao_audit.auditor = Ec_Member.Id) auditorb GROUP BY projectId)shb ON pj.id=shb.projectId LEFT JOIN (select projectId,auditor as auditorC from eao_audit where auditType ='一审')auditorc  ON pj.id = auditorc.projectId LEFT JOIN (select projectId,auditor as auditorD from eao_audit where auditType ='二审')auditord  ON pj.id = auditord.projectId LEFT JOIN (select projectId,auditor as auditorE from eao_audit where auditType ='初审')auditore ON pj.id = auditore.projectId LEFT JOIN (select projectId,auditor as auditorF from eao_audit where auditType ='复审')auditorf  ON pj.id = auditorf.projectId LEFT JOIN (select projectId,auditor as auditorG from eao_audit where auditType ='终审')auditorg  ON pj.id = auditorg.projectId WHERE IsAssign =1 AND IsFcAssign =1 AND pj.Company=? ORDER BY PerjectTime DESC limit ?,?",
						company, pageIndex, pageSize);
				DataTable dt = new Q(
						"select COUNT(*) as c,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,rs.RealName as CommitName,fz.LeaderName,StaffNames,Auditors from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson =rs.Id LEFT JOIN (SELECT eao_project_info.id as projectId,perjectLeader,Ec_Member.Id,RealName as leaderName  from eao_project_info LEFT JOIN Ec_Member on eao_project_info.perjectLeader = Ec_Member.Id)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames from(select  projectId,RealName as staffsName from eao_project_staff as staff LEFT JOIN Ec_Member on staff.staffName=Ec_Member.Id)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN (select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors from (select projectId,auditor,RealName as audname,auditType from eao_audit LEFT JOIN Ec_Member on eao_audit.auditor = Ec_Member.Id) auditorb GROUP BY projectId)shb ON pj.id=shb.projectId WHERE IsAssign = 1 AND pj.Company=? ",
						company).fetch();
				Integer count = 0;
				for (DataRow dr : dt) {
					count = dr.getInt("c");
				}
				List<EaoProjectAssignVo> lists = new ArrayList<EaoProjectAssignVo>();
				for (DataRow drTwo : q.fetch()) {
					EaoProjectAssignVo pvo = new EaoProjectAssignVo();
					pvo.setIsFcAssign(drTwo.getString(0));
					Map<String, String> map = new HashMap<String, String>();
					map.put("一审", drTwo.getString(1));
					map.put("二审", drTwo.getString(2));
					map.put("初审", drTwo.getString(3));
					map.put("复审", drTwo.getString(4));
					map.put("终审", drTwo.getString(5));
					pvo.setAuditorsId(map);
					pvo.setId(drTwo.getString(6));
					pvo.setProjectNumber(drTwo.getString(7));
					pvo.setProjectName(drTwo.getString(8));
					pvo.setProjectLevel(drTwo.getString(9));
					pvo.setReportType(drTwo.getString(10));
					pvo.setBuildAddress(drTwo.getString(11));
					pvo.setCommitName(drTwo.getString(12));
					pvo.setCommitNameId(drTwo.getString(13));
					pvo.setLeaderName(drTwo.getString(14));
					pvo.setLeaderNameId(drTwo.getString(15));
					pvo.setStaffNames(drTwo.getString(16));
					pvo.setStaffNameIds(drTwo.getString(17));
					pvo.setAuditors(drTwo.getString(18));
					pvo.setTof(drTwo.getString(19));
					lists.add(pvo);
				}
				$S("data", lists);
				// $S("data", q.fetch());
				this.Response.put("count", count);

			} else {
				Q q = new Q(
						"select pj.IsFcAssign,pj.Id,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,RealName as CommitName,fz.LeaderName,StaffNames,StaffName,Auditors,pj.Tof from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson =rs.Id LEFT JOIN (SELECT eao_project_info.id as projectId,perjectLeader,Ec_Member.Id,RealName as leaderName  from eao_project_info LEFT JOIN Ec_Member on eao_project_info.perjectLeader = Ec_Member.Id)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames ,GROUP_CONCAT(staffName) as staffName from(select staff.staffName, projectId,RealName as staffsName from eao_project_staff as staff LEFT JOIN Ec_Member on staff.staffName=Ec_Member.Id)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN (select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors from (select projectId,auditor,RealName as audname,auditType from eao_audit LEFT JOIN Ec_Member on eao_audit.auditor = Ec_Member.Id) auditorb GROUP BY projectId)shb ON pj.id=shb.projectId WHERE IsAssign =0 AND IsFcAssign =1 AND pj.Company=?  ORDER BY PerjectTime DESC LIMIT ?,?",
						company, pageIndex, pageSize);
				DataTable dtTwo = new Q(
						"select count(*)as c from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson = rs.Id  WHERE IsAssign = 0 AND IsFcAssign =1 AND pj.Company=? ",
						company).fetch();
				Integer cc = 0;
				for (DataRow dr : dtTwo) {
					cc = dr.getInt("c");
				}
				this.Response.put("count", cc);
				$S("data", q.fetch());
			}
		} else if ("3".equals(level)) {
			if (!StringUtils.isEmpty(isAssign)) { // isAssign不为空 返回已分配的数据 为空返回未分配数据

				Q q = new Q(
						"select pj.IsFcAssign,AuditorC,AuditorD,AuditorE,AuditorF,AuditorG,pj.Id,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,RealName as CommitName,pj.CreatePerson as commit_name_id,fz.LeaderName,pj.PerjectLeader as leader_name_id,staffNames,staffNameIds,auditors,pj.tof,auditorsId from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson =rs.Id LEFT JOIN (SELECT eao_project_info.id as projectId,perjectLeader,Ec_Member.Id,RealName as leaderName  from eao_project_info LEFT JOIN Ec_Member on eao_project_info.perjectLeader = Ec_Member.Id)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames,GROUP_CONCAT(staffNameId ) as staffNameIds from(select  projectId,RealName as staffsName,staffName as staffNameId from eao_project_staff as staff LEFT JOIN Ec_Member on staff.staffName=Ec_Member.Id)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN(select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors,GROUP_CONCAT(auditor) as auditorsId from (select projectId,auditor,RealName as audname,auditType from eao_audit LEFT JOIN Ec_Member on eao_audit.auditor = Ec_Member.Id) auditorb GROUP BY projectId)shb ON pj.id=shb.projectId LEFT JOIN (select projectId,auditor as auditorC from eao_audit where auditType ='一审')auditorc  ON pj.id = auditorc.projectId LEFT JOIN (select projectId,auditor as auditorD from eao_audit where auditType ='二审')auditord  ON pj.id = auditord.projectId LEFT JOIN (select projectId,auditor as auditorE from eao_audit where auditType ='初审')auditore ON pj.id = auditore.projectId LEFT JOIN (select projectId,auditor as auditorF from eao_audit where auditType ='复审')auditorf  ON pj.id = auditorf.projectId LEFT JOIN (select projectId,auditor as auditorG from eao_audit where auditType ='终审')auditorg  ON pj.id = auditorg.projectId WHERE  IsFcAssign =1 AND pj.Company=?  AND pj.BranchInnerCode=? ORDER BY PerjectTime DESC limit ?,?",
						company, bcode, pageIndex, pageSize);
				DataTable dt = new Q(
						"select COUNT(*) as c,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,RealName as CommitName,fz.LeaderName,StaffNames,Auditors from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson =rs.Id LEFT JOIN (SELECT eao_project_info.id as projectId,perjectLeader,Ec_Member.Id,RealName as leaderName  from eao_project_info LEFT JOIN Ec_Member on eao_project_info.perjectLeader = Ec_Member.Id)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames from(select  projectId,RealName as staffsName from eao_project_staff as staff LEFT JOIN Ec_Member on staff.staffName=Ec_Member.Id)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN (select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors from (select projectId,auditor,RealName as audname,auditType from eao_audit LEFT JOIN Ec_Member on eao_audit.auditor = Ec_Member.Id) auditorb GROUP BY projectId)shb ON pj.Id=shb.projectId WHERE IsAssign = 1 AND pj.Company=? AND pj.BranchInnerCode=?",
						company, bcode).fetch();
				Integer count = 0;
				for (DataRow dr : dt) {
					count = dr.getInt("c");
				}
				List<EaoProjectAssignVo> lists = new ArrayList<EaoProjectAssignVo>();
				for (DataRow drTwo : q.fetch()) {
					EaoProjectAssignVo pvo = new EaoProjectAssignVo();
					pvo.setIsFcAssign(drTwo.getString(0));
					Map<String, String> map = new HashMap<String, String>();
					map.put("一审", drTwo.getString(1));
					map.put("二审", drTwo.getString(2));
					map.put("初审", drTwo.getString(3));
					map.put("复审", drTwo.getString(4));
					map.put("终审", drTwo.getString(5));
					pvo.setAuditorsId(map);
					pvo.setId(drTwo.getString(6));
					pvo.setProjectNumber(drTwo.getString(7));
					pvo.setProjectName(drTwo.getString(8));
					pvo.setProjectLevel(drTwo.getString(9));
					pvo.setReportType(drTwo.getString(10));
					pvo.setBuildAddress(drTwo.getString(11));
					pvo.setCommitName(drTwo.getString(12));
					pvo.setCommitNameId(drTwo.getString(13));
					pvo.setLeaderName(drTwo.getString(14));
					pvo.setLeaderNameId(drTwo.getString(15));
					pvo.setStaffNames(drTwo.getString(16));
					pvo.setStaffNameIds(drTwo.getString(17));
					pvo.setAuditors(drTwo.getString(18));
					pvo.setTof(drTwo.getString(19));
					lists.add(pvo);
				}
				$S("data", lists);
				this.Response.put("count", count);
				// $S("data", q.fetch());
			} else {
				Q q = new Q(
						"select pj.IsFcAssign,pj.Id,pj.ProjectNumber,pj.ProjectName,ProjectLevel,pj.ReportType,pj.BuildAddress,RealName as CommitName,fz.LeaderName,StaffNames,StaffName,Auditors,pj.Tof from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.createPerson =rs.Id LEFT JOIN (SELECT eao_project_info.id as projectId,perjectLeader,Ec_Member.Id,RealName as leaderName  from eao_project_info LEFT JOIN Ec_Member on eao_project_info.perjectLeader = Ec_Member.Id)AS fz ON pj.id = fz.projectId LEFT JOIN (select projectId,GROUP_CONCAT(staffsName) as staffNames,GROUP_CONCAT(staffName) as staffName from(select  projectId,RealName as staffsName,staff.staffName from eao_project_staff as staff LEFT JOIN Ec_Member on staff.staffName=Ec_Member.Id)as cy GROUP BY projectId)as cys ON pj.id = cys.projectId LEFT JOIN (select projectId,GROUP_CONCAT(auditType ,'工程师：',audname order by auditType )as auditors from (select projectId,auditor,RealName as audname,auditType from eao_audit LEFT JOIN Ec_Member on eao_audit.auditor = Ec_Member.Id) auditorb GROUP BY projectId)shb ON pj.id=shb.projectId WHERE IsAssign =0  AND  IsFcAssign = 0 AND pj.Company=? AND pj.BranchInnerCode=? ORDER BY PerjectTime DESC LIMIT ?,?",
						company, bcode, pageIndex, pageSize);
				DataTable dtTwo = new Q(
						"select count(*)as c from eao_project_info as pj LEFT JOIN Ec_Member as rs ON pj.CreatePerson = rs.Id  WHERE IsAssign = 0 AND  IsFcAssign = 0 AND pj.Company = ? AND pj.BranchInnerCode= ?",
						company, bcode).fetch();
				Integer cc = 0;
				for (DataRow dr : dtTwo) {
					cc = dr.getInt("c");
				}
				this.Response.put("count", cc);
				$S("data", q.fetch());
			}
		} else {
			f("无此权限");
			return;
		}
	}

	/**
	 * 从resource表工查询种下成员
	 */
	@Priv(loginType = LoginType.Member)
	public void showEngineer() {
		String type = $V("Type"); // type 为空时查询未人员表 不为空时查询为 工程表
		String loginer = Long.toString(Member.getUID());
		String company = "";
		List<String> bcode = new ArrayList<>();
//		DataTable dt0 = new Q("select Company,BranchInnerCode from Mh_Resource where Member =?", loginer).fetch();
		DataTable dataTable0 = new DataTable();
		if ("Ent".equals(Member.getType())) {
			DataTable dt0 = new Q(
					"select BranchInnerCode from Mh_Branch where company = ? and ParentInnerCode = ? and CompanyType = 2",
					Member.getCompany(), Member.getBranchInnerCode()).fetch();
			bcode.add(Member.getBranchInnerCode());
			for (DataRow dr0 : dt0) {
				bcode.add(dr0.getString(0));
			}
		} else {
			dataTable0 = new Q("select ParentInnerCode from Mh_Branch where Company =? and BranchInnerCode = ?",
					Member.getCompany(), Member.getBranchInnerCode()).fetch();
			if (dataTable0.getRowCount() != 0) {
				if ("0".equals(dataTable0.get(0, 0))) {
					DataTable dt0 = new Q(
							"select BranchInnerCode from Mh_Branch where company = ? and ParentInnerCode = ? and CompanyType = 2",
							Member.getCompany(), Member.getBranchInnerCode()).fetch();
					bcode.add(Member.getBranchInnerCode());
					for (DataRow dr0 : dt0) {
						bcode.add(dr0.getString(0));
					}
				} else {
					DataTable dt0 = new Q(
							"select BranchInnerCode from Mh_Branch where company = ? and ParentInnerCode = ? and CompanyType = 2",
							Member.getCompany(), dataTable0.get(0, 0)).fetch();
					for (DataRow dr0 : dt0) {
						bcode.add(dr0.getString(0));
					}
				}
			}
		}
		String IsEngineer = new Q(" select IsEngineer from eao_is_engineer where Member = ? ", loginer).executeString();
		String parentId = new Q(" select ParentId from eao_Position where id = ? ", IsEngineer).executeString();
		if (StringUtil.isNotEmpty(parentId)) {
			IsEngineer = parentId;
		}

//		for (DataRow dr0 : dt0) {
		company = Long.toString(Member.getCompany());
//			bcode.add(dr0.getString(1));
//		}

		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		pageIndex = (pageIndex) * pageSize;
		if (!StringUtils.isEmpty(type)) {
			if ("1".equals(IsEngineer) || "2".equals(IsEngineer) || "Ent".equals(Member.getType())
					|| "3".equals(IsEngineer)) {
//				Q q = new Q(
//						"select mr.Member,FullName,fenshuliang,shuju,shuliang,BranchInnerCode from (select auditor,GROUP_CONCAT(report_type,':',zongshu )as shuju from (select auditor,report_type,zongshu from (select auditor,COUNT(project_id) as zongshu,report_type from eao_audit INNER JOIN eao_project_info  on eao_audit.project_id = eao_project_info.id  where eao_audit.stats = '审核中' And eao_project_info.report_type='报告书' GROUP BY auditor UNION select auditor,COUNT(project_id) as zongshu,report_type from eao_audit INNER JOIN eao_project_info  on eao_audit.project_id = eao_project_info.id  where eao_audit.stats = '审核中' And eao_project_info.report_type='报告表' GROUP BY auditor) as cxb GROUP BY auditor,report_type) as sssc GROUP BY auditor) as cxbs LEFT JOIN (select auditor as auditors,COUNT(project_id) as shuliang from eao_audit WHERE stats ='审核中' group by auditor) as danbiao on cxbs.auditor = danbiao.auditors right JOIN Mh_Resource as mr on cxbs.auditor = mr.Member LEFT JOIN (select staff_name,GROUP_CONCAT(report_type,':',shuliang) as fenshuliang FROM (SELECT staff_name,report_type,COUNT(report_type) as shuliang FROM(select staff_name,report_type FROM eao_project_staff left join eao_project_info ON eao_project_staff.project_id = eao_project_info.id)as fenshu where report_type ='报告书' GROUP BY staff_name UNION SELECT staff_name,report_type,COUNT(report_type) as shuliang FROM(select staff_name,report_type FROM eao_project_staff left join eao_project_info ON eao_project_staff.project_id = eao_project_info.id)as fenshu where report_type ='报告表' GROUP BY staff_name )as cxun GROUP BY staff_name)as xianyoucx ON mr.Member =xianyoucx.staff_name  LEFT JOIN eao_is_engineer on mr.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN  ('1','2','4','5','6') AND Company =? AND BranchInnerCode=? ORDER BY shuliang limit ?,?",
//						company, bcode, pageIndex, pageSize);
//				DataTable dt = new Q(
//						"select COUNT(*) as c from (select auditor,GROUP_CONCAT(report_type,':',zongshu )as shuju from (select auditor,report_type,zongshu from (select auditor,COUNT(project_id) as zongshu,report_type from eao_audit INNER JOIN eao_project_info  on eao_audit.project_id = eao_project_info.id  where eao_audit.stats = '审核中' And eao_project_info.report_type='报告书' GROUP BY auditor UNION select auditor,COUNT(project_id) as zongshu,report_type from eao_audit INNER JOIN eao_project_info  on eao_audit.project_id = eao_project_info.id  where eao_audit.stats = '审核中' And eao_project_info.report_type='报告表' GROUP BY auditor) as cxb GROUP BY auditor,report_type) as sssc GROUP BY auditor) as cxbs LEFT JOIN (select auditor as auditors,COUNT(project_id) as shuliang from eao_audit WHERE stats ='审核中' group by auditor) as danbiao on cxbs.auditor = danbiao.auditors right JOIN Mh_Resource as mr on cxbs.auditor = mr.Member LEFT JOIN (select staff_name,GROUP_CONCAT(report_type,':',shuliang) as fenshuliang FROM (SELECT staff_name,report_type,COUNT(report_type) as shuliang FROM(select staff_name,report_type FROM eao_project_staff left join eao_project_info ON eao_project_staff.project_id = eao_project_info.id)as fenshu where report_type ='报告书' GROUP BY staff_name UNION SELECT staff_name,report_type,COUNT(report_type) as shuliang FROM(select staff_name,report_type FROM eao_project_staff left join eao_project_info ON eao_project_staff.project_id = eao_project_info.id)as fenshu where report_type ='报告表' GROUP BY staff_name )as cxun GROUP BY staff_name)as xianyoucx ON mr.Member =xianyoucx.staff_name  LEFT JOIN eao_is_engineer on mr.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN  ('1','2','4','5','6') AND Company =? AND BranchInnerCode=? ORDER BY shuliang",
//						company, bcode).fetch();
//				Integer count = 0;
//				for (DataRow dr : dt) {
//					count = dr.getInt("c");
//				}
				Integer count = 0;
				AssignJobsUI engineerUI = new AssignJobsUI();
				List<EaoEngineerMemberVo> list = engineerUI.engineerList();
				List<EaoEngineerMemberVo> listAudit = new ArrayList<>();
				for (EaoEngineerMemberVo engineerMemberVo : list) {
					if (engineerMemberVo.getPermissions() == 0) {
						listAudit.add(engineerMemberVo);
						count++;
					}
				}
				int index = this.Request.getInt("PageIndex") * pageSize + pageSize;
				if (index > listAudit.size()) {
					index = listAudit.size();
				}
				this.Response.put("count", count);
				$S("data1", listAudit);
				$S("data", listAudit.subList(this.Request.getInt("PageIndex") * pageSize, index));
			}

		} else {
			if ("1".equals(IsEngineer) || "2".equals(IsEngineer) || "Ent".equals(Member.getType())) {
				Q q = new Q(
						"select  Mh_Resource.Member,FullName,zongshu,fenshuliang,BranchInnerCode from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('1','2','5','6') or ParentId in ('1','2','5','6'))) AND Company =? ",
						company);
				q.and().in("BranchInnerCode", bcode);
				q.append(" ORDER BY zongshu LIMIT ?,?", pageIndex, pageSize);
				Q q1 = new Q(
						"select COUNT(*) as c from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('1','2','5','6') or ParentId in ('1','2','5','6'))) AND Company =?",
						company);
				q1.and().in("BranchInnerCode", bcode);
				q1.append(" ORDER BY zongshu");
				DataTable dt = q1.fetch();
				Integer count = 0;
				for (DataRow dr : dt) {
					count = dr.getInt("c");
				}
				Q q2 = new Q(
						"select  Mh_Resource.Member,FullName,zongshu,fenshuliang,BranchInnerCode from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('1','2','5','6') or ParentId in ('1','2','5','6'))) AND Company =? ",
						company);
				q2.and().in("BranchInnerCode", bcode);
				this.Response.put("count", count);
				$S("data", q.fetch());
				$S("data1", q2.fetch());
			} else {
				Q q = new Q(
						"select  Mh_Resource.Member,FullName,zongshu,fenshuliang,BranchInnerCode from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('3','5','6') or ParentId in ('1','2','5','6'))) AND Company =? ",
						company);
				q.and().in("BranchInnerCode", bcode);
				q.append(" ORDER BY zongshu LIMIT ?,?", pageIndex, pageSize);
				Q q1 = new Q(
						"select COUNT(*) as c from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('3','5','6') or ParentId in ('3','5','6'))) AND Company =?",
						company);
				q1.and().in("BranchInnerCode", bcode);
				q1.append(" ORDER BY zongshu");
				DataTable dt = q1.fetch();
				Integer count = 0;
				if (dt.getRowCount() != 0) {
					for (DataRow dr : dt) {
						count = dr.getInt("c");
					}
				}
				Q q2 = new Q(
						"select  Mh_Resource.Member,FullName,zongshu,fenshuliang,BranchInnerCode from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('3','5','6') or ParentId in ('1','2','5','6'))) AND Company =? ",
						company);
				q2.and().in("BranchInnerCode", bcode);
				this.Response.put("count", count);
				$S("data", q.fetch());
				$S("data1", q2.fetch());
			}
		}

	}

	/**
	 * 根据Mh_Resource表Member统计所涉及项目
	 */
	@Priv(loginType = LoginType.Member)
	public void CountProject() {
		String id = $V("Member");
		if(StringUtils.isEmpty(id)) {
			f("参数传入失败");
		}
		Q q = new Q(
				"select ReportType,Count(*)as NB  from eao_project_info where perjectLeader = ? AND reportType ='报告表' UNION select reportType,Count(*)as NB  from eao_project_info where perjectLeader = ? AND reportType ='报告书'",
				id, id);
		$S("data", q.fetch());
	}

	/**
	 * 重新分配
	 */
	@Priv(loginType = LoginType.Member)
	public void doagain() {
		String projectid = $V("ProjectId"); // 获取项目编号
		String leader = $V("PerjectLeader"); // 获取负责人的resource表id
		String staff = $V("StaffName"); // 获取小组成员数据 多个逗号隔开
		String yname = $V("Yname"); // 一审人工程师
		String ename = $V("Ename"); // 二审人工程师
		String cname = $V("Cname"); // 初审人工程师
		String fname = $V("Fname");// 复审人工程师
		String zname = $V("Zname");// 终审人工程师
		Integer projectType = new Q(" select PerjectType from eao_project_info where Id = ?", projectid).executeInt();
		if (StringUtils.isEmpty(projectid)) {
			f("操作失败");
			return;
		}
		if (projectType == 16) {
			f("项目已入库，人员不可更改！");
			return;
		}
		if (StringUtils.isEmpty(yname) || "0".equals(yname)) {
			yname = new Q(" select Auditor from eao_audit where auditType = '一审' and projectId = ?", projectid)
					.executeString();
		} else {
			String yname1 = new Q(" select Auditor from eao_audit where auditType = '一审' and projectId = ?", projectid)
					.executeString();
			if (projectType >= 6 && !yname.equals(yname1)) {
				f("一审人员不可更改");
				return;
			}
		}
		if (StringUtils.isEmpty(ename) || "0".equals(ename)) {
			ename = new Q(" select Auditor from eao_audit where auditType = '二审' and projectId = ?", projectid)
					.executeString();
		} else {
			String ename1 = new Q(" select Auditor from eao_audit where auditType = '二审' and projectId = ?", projectid)
					.executeString();
			if (projectType >= 7 && !ename.equals(ename1)) {
				f("二审人员不可更改");
				return;
			}
		}
		if (StringUtil.isNotEmpty(cname)) {
			String cname1 = new Q(" select Auditor from eao_audit where auditType = '初审' and projectId = ?", projectid)
					.executeString();
			if (projectType >= 8 && !cname.equals(cname1)) {
				f("初审人员不可更改");
				return;
			}
		}
		if (StringUtil.isNotEmpty(fname)) {
			String fname1 = new Q(" select Auditor from eao_audit where auditType = '复审' and projectId = ?", projectid)
					.executeString();
			if (projectType >= 9 && !fname.equals(fname1)) {
				f("复审人员不可更改");
				return;
			}
		}
		if (StringUtil.isNotEmpty(zname)) {
			String zname1 = new Q(" select Auditor from eao_audit where auditType = '终审' and projectId = ?", projectid)
					.executeString();
			if (projectType >= 10 && !zname.equals(zname1)) {
				f("终审人员不可更改");
				return;
			}
		}
		if (StringUtils.isEmpty(leader) || "0".equals(leader)) {
			leader = new Q(" select PerjectLeader from eao_project_info where id = ?", projectid).executeString();
		}
		if (StringUtils.isEmpty(staff) || "0".equals(staff)) {
			staff = new Q(" select GROUP_CONCAT(StaffName) as Staff from eao_project_staff where projectId = ?",
					projectid).executeString();
		}
		if ((StringUtil.isNotEmpty(yname) || "0".equals(yname))
				&& (StringUtil.isNotEmpty(ename) || "0".equals(ename))) {
			if (yname.equals(ename)) {
				f("审核人员不能重复");
				return;
			}
			if ((StringUtil.isNotEmpty(cname) || "0".equals(cname))
					&& (StringUtil.isNotEmpty(fname) || "0".equals(fname))
					&& (StringUtil.isNotEmpty(zname) || "0".equals(zname))) {
				if (yname.equals(cname) || yname.equals(fname) || yname.equals(zname) || ename.equals(cname)
						|| ename.equals(fname) || ename.equals(zname)) {
					f("审核人员不能重复");
					return;
				}
			}
		}
		if ((StringUtil.isNotEmpty(cname) || "0".equals(cname)) && (StringUtil.isNotEmpty(fname) || "0".equals(fname))
				&& (StringUtil.isNotEmpty(zname) || "0".equals(zname))) {
			if (cname.equals(fname) || cname.equals(zname) || fname.equals(zname)) {
				f("审核人员不能重复");
				return;
			}
		}
		if (StringUtil.isNotEmpty(leader) && (StringUtil.isNotEmpty(cname) || "0".equals(cname))
				&& (StringUtil.isNotEmpty(fname) || "0".equals(fname))
				&& (StringUtil.isNotEmpty(zname) || "0".equals(zname))) {
			if (leader.equals(cname) || leader.equals(fname) || leader.equals(zname)) {
				f("项目负责人不可做(初/复/终)审人员");
				return;
			}
		}
		if (StringUtil.isNotEmpty(staff) && (StringUtil.isNotEmpty(cname) || "0".equals(cname))
				&& (StringUtil.isNotEmpty(fname) || "0".equals(fname))
				&& (StringUtil.isNotEmpty(zname) || "0".equals(zname))) {
			String Staff_name[] = staff.split(",");
			for (String string : Staff_name) {
				if (string.equals(cname) || string.equals(fname) || string.equals(zname)) {
					f("项目组成员不可做(初/复/终)审人员");
					return;
				}
			}
		}

		Transaction transactionTwo = new Transaction();
		Boolean bl = true;
		if (!StringUtils.isEmpty(staff) && !"0".equals(staff)) {
			String staffs[] = staff.split(",");
			int stf[] = new int[staffs.length];
			for (int i = 0; i < staffs.length; i++) {
				stf[i] = Integer.parseInt(staffs[i]);
				if (Integer.parseInt(leader) == stf[i]) {
					bl = false;
				}
			}
			Q q = new Q("delete from eao_project_staff where").in("ProjectId", projectid);
			transactionTwo.add(q);
			List<String> list = AssignJobsUI.memberId();
			this.Response.put("list", list);
			HashSet<String> set = new HashSet<String>(staffs.length);
			List<String> result = new ArrayList<String>(staffs.length);
			for (String str : staffs) {
				if (set.add(str)) {
					result.add(str);
				}
			}
			for (String sta : result) { // 设置小组成员
				for (String string : list) {
					this.Response.put("string", string + ":" + sta);
					if (string.equals(sta) && !leader.equals(sta)) {
						EaoProjectStaff entity = new EaoProjectStaff();
						entity.setId(UUID.randomUUID().toString());
						entity.setProjectId(projectid);
						entity.setStaffName(Integer.valueOf(sta));
						transactionTwo.insert(entity);
					}
				}
				if (leader.equals(sta)) {
					EaoProjectStaff entity = new EaoProjectStaff();
					entity.setId(UUID.randomUUID().toString());
					entity.setProjectId(projectid);
					entity.setStaffName(Integer.valueOf(sta));
					transactionTwo.insert(entity);
				}
			}
			if (bl) {
				EaoProjectStaff entity = new EaoProjectStaff();
				entity.setId(UUID.randomUUID().toString());
				entity.setProjectId(projectid);
				entity.setStaffName(Integer.parseInt(leader));
				transactionTwo.insert(entity);
			}
		}
		DataTable dtOne = new Q(" select * from eao_project_info where Id = ?", projectid).fetch();
		EaoProjectInfo old = new EaoProjectInfo();
		for (DataRow dr : dtOne) {
			old.setValue(dr);
		}
		if (!StringUtil.isEmpty(leader)) {
			int leaderi = Integer.parseInt(leader);
			old.setPerjectLeader(leaderi);
			transactionTwo.update(old);
		}
		String pid = projectid;
		if (!StringUtil.isEmpty(yname) && !StringUtil.isEmpty(ename) && !"0".equals(yname) && !"0".equals(ename)) {
			String ysname = yname;
			String esname = ename;
			DataTable ysdt = new Q(" select * from eao_audit where ProjectId = ? AND AuditType = ?", pid, "一审").fetch();
			DataTable esdt = new Q(" select * from eao_audit where ProjectId = ? AND AuditType = ?", pid, "二审").fetch();
			EaoAudit ysold = new EaoAudit();
			EaoAudit esold = new EaoAudit();
			ysold.setValue(ysdt.get(0));
			ysold.setAuditor(ysname);
			esold.setValue(esdt.get(0));
			esold.setAuditor(esname);
			transactionTwo.update(ysold);
			transactionTwo.update(esold);
		}
		if (!StringUtils.isEmpty(cname) && !StringUtils.isEmpty(fname) && !StringUtils.isEmpty(zname)
				&& !"0".equals(cname) && !"0".equals(fname) && !"0".equals(zname)) {
			DataTable cdt = new Q(" select * from eao_audit where ProjectId = ? AND AuditType = ?", pid, "初审").fetch();
			DataTable fdt = new Q(" select * from eao_audit where ProjectId = ? AND AuditType = ?", pid, "复审").fetch();
			DataTable zdt = new Q(" select * from eao_audit where ProjectId = ? AND AuditType = ?", pid, "终审").fetch();
			EaoAudit cold = new EaoAudit();
			EaoAudit fold = new EaoAudit();
			EaoAudit zold = new EaoAudit();
			cold.setValue(cdt.get(0));
			cold.setAuditor(cname);
			fold.setValue(fdt.get(0));
			fold.setAuditor(fname);
			zold.setValue(zdt.get(0));
			zold.setAuditor(zname);
			transactionTwo.update(cold);
			transactionTwo.update(fold);
			transactionTwo.update(zold);
		}
		if (transactionTwo.commit()) {
			s(Lang.get("Common.ExecuteSuccess"));
		} else {
			f(Lang.get("Common.ExecuteFailed"));
		}
	}

	public static List<String> memberId() {
		List<String> list = new ArrayList<>();
		String loginer = Long.toString(Member.getUID());
		List<String> bcode = new ArrayList<>();
		DataTable dataTable0 = new DataTable();
		if ("Ent".equals(Member.getType())) {
			DataTable dt0 = new Q("select BranchInnerCode from Mh_Branch where ParentInnerCode = ? and CompanyType = 2",
					Member.getBranchInnerCode()).fetch();
			bcode.add(Member.getBranchInnerCode());
			for (DataRow dr0 : dt0) {
				bcode.add(dr0.getString(0));
			}
		} else {
			dataTable0 = new Q("select ParentInnerCode from Mh_Branch where Company =? and BranchInnerCode = ?",
					Member.getCompany(), Member.getBranchInnerCode()).fetch();
			if (dataTable0.getRowCount() != 0) {
				if ("0".equals(dataTable0.get(0, 0))) {
					DataTable dt0 = new Q(
							"select BranchInnerCode from Mh_Branch where ParentInnerCode = ? and CompanyType = 2",
							Member.getBranchInnerCode()).fetch();
					bcode.add(Member.getBranchInnerCode());
					for (DataRow dr0 : dt0) {
						bcode.add(dr0.getString(0));
					}
				} else {
					DataTable dt0 = new Q(
							"select BranchInnerCode from Mh_Branch where ParentInnerCode = ? and CompanyType = 2",
							dataTable0.get(0, 0)).fetch();
					for (DataRow dr0 : dt0) {
						bcode.add(dr0.getString(0));
					}
				}
			}
		}
		String IsEngineer = new Q(" select IsEngineer from eao_is_engineer where Member = ? ", loginer).executeString();
		String parentId = new Q(" select ParentId from eao_Position where id = ? ", IsEngineer).executeString();
		if (StringUtil.isNotEmpty(parentId)) {
			IsEngineer = parentId;
		}
		if ("1".equals(IsEngineer) || "2".equals(IsEngineer) || "Ent".equals(Member.getType())) {
			Q q = new Q(
					"select  Mh_Resource.Member,FullName,zongshu,fenshuliang,BranchInnerCode from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('1','2','5','6') or ParentId in ('1','2','5','6'))) AND Company =? ",
					Member.getCompany());
			q.and().in("BranchInnerCode", bcode);
			DataTable dataTable = q.fetch();
			if (dataTable.getRowCount() != 0) {
				for (DataRow dataRow : dataTable) {
					list.add(dataRow.getString("Member"));
				}
			}
			return list;
		} else {
			Q q = new Q(
					"select  Mh_Resource.Member,FullName,zongshu,fenshuliang,BranchInnerCode from Mh_Resource LEFT JOIN (select staffName,COUNT(projectId) AS zongshu FROM eao_project_staff GROUP BY staffName) as zongshub ON Mh_Resource.Member = zongshub.staffName LEFT JOIN (select staffName,GROUP_CONCAT(reportType,':',shuliang) as fenshuliang FROM (SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告书' GROUP BY staffName UNION SELECT staffName,reportType,COUNT(reportType) as shuliang FROM(select staffName,reportType FROM eao_project_staff left join eao_project_info ON eao_project_staff.projectId = eao_project_info.Id)as fenshu where reportType ='报告表' GROUP BY staffName )as cxun GROUP BY staffName) as fenshub on Mh_Resource.Member = fenshub.staffName LEFT JOIN eao_is_engineer on Mh_Resource.Member = eao_is_engineer.Member WHERE eao_is_engineer.IsEngineer IN (SELECT id FROM eao_Position where (type = Company or type is null) and id not in (SELECT parentId FROM eao_Position where type = Company and ParentId is not null) and (id in ('3','5','6') or ParentId in ('3','5','6'))) AND Company =? ",
					Member.getCompany());
			q.and().in("BranchInnerCode", bcode);
			DataTable dataTable = q.fetch();
			if (dataTable.getRowCount() != 0) {
				for (DataRow dataRow : dataTable) {
					list.add(dataRow.getString("Member"));
				}
			}
			return list;
		}
	}

	@Priv(loginType = LoginType.Member)
	public List<EaoEngineerMemberVo> engineerList() {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		List<EaoEngineerMemberVo> emList = new ArrayList<EaoEngineerMemberVo>();
		Set<Long> set = new HashSet<>();
		Q q = new Q("select count(1) as num from eao_engineer_member where ");
		Q q1 = new Q("select * from eao_engineer_member where ");
		if ("Ent".equals(Member.getType())) {
			q.append("Company = ?", Member.getUID());
			q1.append("Company = ?", Member.getUID());
		} else {
			q.append("Company = ?", Member.getCompany());
			q1.append("Company = ?", Member.getCompany());
		}
		DataTable dataTable = q.fetch();
		DataTable dataNum = q1.fetch();
		for (DataRow dataRow : dataNum) {
			EaoEngineerMemberVo em = new EaoEngineerMemberVo();
			em.setMember(dataRow.getLong("Member"));
			em.setUserName(dataRow.getString("UserName"));
			em.setApplicant(dataRow.getString("Applicant"));
			em.setRegNumber(dataRow.getString("RegNumber"));
			em.setProfessionalNumber(dataRow.getString("ProfessionalNumber"));
			em.setRegisterClass(dataRow.getString("RegisterClass"));
			if (!StringUtils.isEmpty(dataRow.getDate("StartTime")))
				em.setStartTime(sf.format(dataRow.getDate("StartTime")).replaceAll("-", "."));

			if (!StringUtils.isEmpty(dataRow.getDate("EndTime")))
				em.setEndTime(sf.format(dataRow.getDate("EndTime")).replaceAll("-", "."));

			em.setIntegrityMessage(dataRow.getString("IntegrityMessage"));
			em.setProvince(dataRow.getString("Province"));
			em.setPermissions(dataRow.getInt("Permissions"));
			em.setRegNumberId(dataRow.getLong("RegNumberId"));
			em.setCompany(dataRow.getLong("Company"));
			em.setProjectNumber("");
			set.add(dataRow.getLong("Member"));
			emList.add(em);
		}
		Q q2 = new Q(
				" select au.Auditor,i.ReportType ,count(1) as bgb from eao_project_info as i LEFT JoIN eao_audit au on i.Id =au.ProjectId where (au.Stats = '未提交' or au.Stats = '审核中')");
		q2.and().in(" au.Auditor ", set);
		q2.append("GROUP BY i.ReportType , au.Auditor");
		DataTable table2 = q2.fetch();

		if (table2.getRowCount() > 0) {
			for (EaoEngineerMemberVo engineerMemberVo : emList) {
				String report_type = "";
				for (DataRow dataRow : table2) {
					if (dataRow.get(0).equals(engineerMemberVo.getMember().toString())) {
						String type = dataRow.getString("ReportType");
						if (StringUtils.isEmpty(type))
							type = "无分类";
						if (StringUtils.isEmpty(report_type)) {
							report_type = type + dataRow.getLong("bgb");
						} else {
							report_type += type + dataRow.getLong("bgb");
						}
					}
				}
				engineerMemberVo.setProjectNumbers(report_type);
			}
		}
		Q q3 = new Q(
				" select ps.StaffName, ReportType ,count(1) as bgb from eao_project_info as pi inner JOIN (select projectId , StaffName from eao_project_staff where ");
		q3.in(" StaffName ", set);
		q3.append(") as ps on ps.ProjectId =pi.Id where pi.PerjectType != '16' GROUP BY pi.ReportType ,ps.StaffName");
		DataTable table3 = q3.fetch();

		if (table3.getRowCount() > 0) {
			for (EaoEngineerMemberVo engineerMemberVo : emList) {
				String report_type = "";
				for (DataRow dataRow : table3) {
					if (dataRow.getString(0).equals(engineerMemberVo.getMember().toString())) {
						String type = dataRow.getString("ReportType");
						if (StringUtils.isEmpty(type))
							type = "无分类";
						if (StringUtils.isEmpty(report_type)) {
							report_type = type + dataRow.getLong("bgb");
						} else {
							report_type += type + dataRow.getLong("bgb");
						}
					}
				}
				engineerMemberVo.setProjectNumber(report_type);
			}
		}
		Integer total = 0;
		if (dataTable.getRowCount() > 0) {
			total = dataTable.get(0).getInt("num");
		}
		this.Response.put("emList", emList);
		this.Response.put("total", total);
		return emList;
	}
}
